using Uantek.Device.Communication.Models;

namespace Uantek.Device.Communication.Protocols.Interfaces
{
    /// <summary>
    /// 通信传输接口
    /// </summary>
    public interface ICommunicationTransport : IDisposable
    {
        /// <summary>
        /// 传输类型（TCP、UDP、串口等）
        /// </summary>
        string TransportType { get; }

        /// <summary>
        /// 连接状态
        /// </summary>
        bool IsConnected { get; }

        /// <summary>
        /// 连接配置信息
        /// </summary>
        string ConnectionInfo { get; }

        /// <summary>
        /// 数据接收事件
        /// </summary>
        event EventHandler<byte[]>? DataReceived;

        /// <summary>
        /// 连接状态变化事件
        /// </summary>
        event EventHandler<bool>? ConnectionStatusChanged;

        /// <summary>
        /// 连接到设备
        /// </summary>
        /// <param name="connectionParameters">连接参数</param>
        /// <returns>连接结果</returns>
        Task<CommunicationResult> ConnectAsync(Dictionary<string, object> connectionParameters);

        /// <summary>
        /// 断开连接
        /// </summary>
        /// <returns>断开结果</returns>
        Task<CommunicationResult> DisconnectAsync();

        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="data">要发送的数据</param>
        /// <returns>发送结果</returns>
        Task<CommunicationResult> SendDataAsync(byte[] data);

        /// <summary>
        /// 发送数据并等待响应
        /// </summary>
        /// <param name="data">要发送的数据</param>
        /// <param name="timeout">超时时间（毫秒）</param>
        /// <returns>响应数据</returns>
        Task<CommunicationResult<byte[]>> SendAndReceiveAsync(byte[] data, int timeout = 5000);

        /// <summary>
        /// 配置传输参数
        /// </summary>
        /// <param name="parameters">参数</param>
        /// <returns>配置结果</returns>
        Task<CommunicationResult> ConfigureAsync(Dictionary<string, object> parameters);
    }
}